<!DOCTYPE html>
<!-- Copyright 2020 the V8 project authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->

<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Indicium</title>
  <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
  <!-- <link rel="icon" type="image/png" href="/images/favicon.png"/> -->
  <script type="module" src="index.mjs"></script>
  <link rel="stylesheet" type="text/css" href="./index.css">
  <style>
    .theme-switch-wrapper {
      display: inline-block;
      align-items: center;
    }

    .theme-switch {
      display: inline-block;
      height: 16px;
      position: relative;
      width: 38px;
    }

    .theme-switch input {
      display: none;
    }

    .slider {
      background-color: var(--primary-color);
      bottom: 0;
      cursor: pointer;
      left: 0;
      position: absolute;
      right: 0;
      top: 0;
      border-radius: 34px;
    }

    .slider:before {
      background-color: var(--surface-color);
      position: absolute;
      height: 10px;
      width: 10px;
      bottom: 3px;
      content: "";
      left: 4px;
      border-radius: 50%;
    }

    input:checked+.slider:before {
      transform: translateX(20px);
    }

    #container.initial {
      display: none;
    }

    #container.loaded {
      display: grid;
      align-content: center;
      grid-template-columns: repeat(auto-fit, minmax(400px, 800px));
      grid-template-rows: repeat(auto-fit, minmax(400px, 800px));
      grid-auto-flow: dense;
      grid-gap: 1em;
    }

    #container.loaded>#timeline-panel {
      grid-column: span 2;
      overflow: scroll;
    }
    dt::after  {
      content: ":";
    }
  </style>
  <script type="module">
    import { App } from './index.mjs';

    globalThis.app = new App("#log-file-reader", "#map-panel",
      "#timeline-panel", "#ic-panel", "#map-track", "#ic-track",
      "#source-panel");
  </script>
</head>

<body>
  <section id="file-reader">
    <log-file-reader id="log-file-reader"></log-file-reader>
  </section>

  <section id="container" class="initial">
    <timeline-panel id="timeline-panel">
      <timeline-track id="map-track"></timeline-track>
      <timeline-track id="ic-track"></timeline-track>
    </timeline-panel>
    <map-panel id="map-panel"></map-panel>
    <ic-panel id="ic-panel" onchange="app.handleSelectIc(event)"></ic-panel>
    <source-panel id="source-panel"></source-panel>
  </section>

  <section id="settings">
    <h2>Settings</h2>
    <span>Theme:</span>
    <div class="theme-switch-wrapper">
      <label class="theme-switch" for="theme-switch-input">
        <input type="checkbox" id="theme-switch-input" />
        <div class="slider"></div>
      </label>
    </div>
  </section>

  <section id="instructions">
    <h2>Instructions</h2>
    <p>
      Unified web interface to analyse runtime information stored in the v8 log.
    </p>
    For generating a v8.log file from <a href="https://v8.dev/docs/build">d8</a>:
    <ul>
      <li>
        <code>/path/do/d8 --trace-maps --trace_ic --log-source-code $FILE</code>
      </li>
    </ul>
    For generating a v8.log file from Chrome:
    <ul>
      <li>
        <code>/path/to/chrome --user-data-dir=/var/tmp/chr$RANDOM --no-sandbox
        --js-flags='--trace-ic --trace-maps --log-source-code’
        $WEBSITE_URL</code>
      </li>
    </ul>

    <h3>Log Options:</h3>
    <dl class="d8-options">
      <dt><code>--trace-maps</code></dt>
      <dd>Log<a href="https://v8.dev/blog/fast-properties" target="_blank">
          Maps</a></dd>
      <dt><code>--trace-ic</code></dt>
      <dd>Log
        <a href="https://mathiasbynens.be/notes/shapes-ics" target="_blank">
          ICs</a></dd>
      <dt><code>--log-source-code</code></dt>
      <dd>Log source code</dd>
    </dl>

    <h3>Keyboard Shortcuts for Navigation</h3>
    <dl>
      <dt><kbd>SHIFT</kbd> + <kbd>Arrow Up</kbd></dt>
      <dd>Follow Map transition forward (first child)</dd>

      <dt><kbd>SHIFT</kbd> + <kbd>Arrow Down</kbd></dt>
      <dd>Follow Map transition backwards</dd>

      <dt><kbd>Arrow Up</kbd></dt>
      <dd>Go to previous Map chunk</dd>

      <dt><kbd>Arrow Down</kbd></dt>
      <dd>Go to next Map in chunk</dd>

      <dt><kbd>Arrow Left</kbd></dt>
      <dd>Go to previous chunk</dd>

      <dt><kbd>Arrow Right</kbd></dt>
      <dd>Go to next chunk</dd>

      <dt><kbd>+</kbd></dt>
      <dd>Timeline zoom in</dd>

      <dt><kbd>-</kbd></dt>
      <dd>Timeline zoom out</dd>
    </dl>
  </section>
</body>

</html>
